import ApiBase from './base/ApiBase';
import type { TPromiseApiResult } from '@/types/apis';
import type { ILoginReq, ILoginRes, IGetUserInfoReq, IGetUserInfoRes } from '@/types/apis/user-api';
import { EUserRole } from '@/types/apis/user-api';
import { mockAxiosRes } from '@hdtd/utils';

export default class UserApi extends ApiBase {
  /**
   * 登录
   * @param data
   * @returns
   */
  login(data: ILoginReq): TPromiseApiResult<ILoginRes> {
    return mockAxiosRes(
      {
        code: 200,
        msg: '请求成功',
        data: {
          token: 'my_token'
        }
      },
      {
        delay: 2000
      }
    );
    return this.httpClient.get('/login', {
      ...this.config,
      params: data
    });
  }

  /**
   * 获取用户信息
   * @param data
   * @returns
   */
  getUserInfo(data: IGetUserInfoReq): TPromiseApiResult<IGetUserInfoRes> {
    return mockAxiosRes({
      code: 200,
      msg: '请求成功',
      data: {
        id: 1,
        roles: [EUserRole.Admin],
        userNme: '张三'
      }
    });
    return this.httpClient.get('/user-info', {
      ...this.config,
      params: data
    });
  }
}
